package com.test.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.test.common.CommonUtils;
import com.test.common.Query;
import com.test.common.R;
import com.test.entity.SysDepartment;
import com.test.manager.SysDepartmentManager;
import com.test.service.SysDepartmentService;

@Component("SysDepartmentService")
public class SysDepartmentServiceImpl implements SysDepartmentService {

	@Autowired
	private SysDepartmentManager sysDepartmentManager;

	@Override
	public List<SysDepartment> listDepartment(Map<String, Object> params) {
		// TODO Auto-generated method stub
		Query query = new Query(params);
		List<SysDepartment> list = sysDepartmentManager.listDepartment(query);
		return list;
	}

	@Override
	public R saveDepartment(SysDepartment department) {
		int count = sysDepartmentManager.save(department);
		return CommonUtils.msg(count);
	}

	@Override
	public R updateDepartment(SysDepartment department) {
		int count = sysDepartmentManager.update(department);
		return CommonUtils.msg(count);
	}

	@Override
	public R removeByDepartCode(String depart_code) {
		int count = sysDepartmentManager.removeByDepartCode(depart_code);
		return CommonUtils.msg(count);
	}

	@Override
	public R listDepartmentTree() {
		List<SysDepartment> list = sysDepartmentManager.listDepartment(null);
		SysDepartment department = new SysDepartment();
		department.setDepart_code("0");
		department.setName("一级部门");
		department.setParent_code("-1");
		department.setOpen(true);
		list.add(department);
		return CommonUtils.msgNotCheckNull(list);
	}

	@Override
	public R listDepartmentByParameter(SysDepartment department) {
		SysDepartment info= sysDepartmentManager.listDepartmentByParameter(department);
		return CommonUtils.msg(info);
	}

}
